#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int v1[100000], v2[100000];
    int n1, n2;

    cin >> n1;
    for (int i = 0; i < n1; i++)
    {
        cin >> v1[i];
    }
    cin >> n2;
    for (int i = 0; i < n2; i++)
    {
        cin >> v2[i];
    }

    sort(v1, v1 + n1, greater<int>());
    sort(v2, v2 + n2, greater<int>());

    int ans = 0;
    int t;
    if(n1 <= n2)
    {
        for (int i = 0; i < n1; i++)
        {
            if(v1[i] > 0)
            {
                t = v1[i] * v2[i];
                if(t > 0)
                {
                    ans += t;
                }
            }
            else
            {
                t = v1[i] * v2[n2 - (n1 - i)];
                if(t > 0)
                {
                    ans += t;
                }
            }
        }
    }
    else
    {
        for (int i = 0; i < n2; i++)
        {
            if(v2[i] > 0)
            {
                t = v1[i] * v2[i];
                if(t > 0)
                {
                    ans += t;
                }
            }
            else
            {
                t = v1[n1 - (n2 - i)] * v2[i];
                if(t > 0)
                {
                    ans += t;
                }
            }
        }
    }

    cout << ans;
}